import * as api from "./index.js";
import {Toast} from "../../utils/toast";
import axios from "axios";
import {showLoading, hideLoading} from "../../utils/loading";
export default function (orderNo, callback, errFn) {
    return new Promise((resolve, reject) => {
        let options = {
            method: "get",
            // url: window.api.local_host + api.gwOrderInfo + `/${orderNo}` + "?token=" + new Date().getTime(),
            url: window.api.trade_host + api.gwOrderInfo + `/${orderNo}` + "?token=" + new Date().getTime(),
            headers: {sessionId: localStorage.getItem("sessionId")}
        }
        axios(options).then(data => {
            console.log("orderInfo", data);
            if (data.status === 200 && data.data.data.length > 0) {
                resolve({
                    status: data.status,
                    returnCode: data.data.returnCode,
                    ...data.data.data[0],
                });
                // resolve(data);
            } else {
                hideLoading();
                // Toast({
                //     message: '订单信息失效',
                //     type: "warn",
                //     duration: 1000
                // });
                resolve({
                    status: data.status,
                    returnCode: data.data.returnCode,
                });
            }
        }).catch(err => {
            hideLoading();
            resolve({
                status: "",
                returnCode: 0,
            });
            console.log(err);
        })
    });
    // let options = {
    //     method: "get",
    //     // url: window.api.local_host + api.gwOrderInfo + `/${orderNo}` + "?token=" + new Date().getTime(),
    //     url: window.api.trade_host + api.gwOrderInfo + `/${orderNo}` + "?token=" + new Date().getTime(),
    //     headers: {sessionId: localStorage.getItem("sessionId")}
    // }
    // return axios(options);
    // axios(options).then(data => {
        
    //     if (callback) {
    //         if (data.status === 200 && data.data.data.length > 0) {
    //             callback(data.data.data[0]);
    //         } else {
    //             // console.log("获取订单失败");
    //             hideLoading();
    //             Toast({
    //                 message: '订单信息失效',
    //                 type: "warn",
    //                 duration: 1000
    //             });
    //             if (errFn) {
    //                 errFn();
    //             }
                
    //         }
            
    //     }
    // }).catch(err => {
    //     hideLoading();
    //     if (errFn) {
    //         errFn();
    //     }
    //     console.log(err);
    // })
    
}